{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e11d4dd4",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.core.display import display, HTML\n",
    "\n",
    "import pandas as pd\n",
    "import numpy as np # linear algebra\n",
    "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n",
    "import glob\n",
    "import os\n",
    "import gc\n",
    "\n",
    "from joblib import Parallel, delayed\n",
    "\n",
    "from sklearn import preprocessing, model_selection\n",
    "from sklearn.preprocessing import MinMaxScaler\n",
    "from sklearn.preprocessing import QuantileTransformer\n",
    "from sklearn.metrics import r2_score\n",
    "\n",
    "import matplotlib.pyplot as plt \n",
    "import seaborn as sns\n",
    "import numpy.matlib\n",
    "from catboost import Pool, CatBoostRegressor\n",
    "\n",
    "path_submissions = '/'\n",
    "\n",
    "target_name = 'target'\n",
    "scores_folds = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ca9ebf0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# data directory\n",
    "data_dir = '../input/optiver-realized-volatility-prediction/'\n",
    "\n",
    "# Function to calculate first WAP\n",
    "def calc_wap1(df):\n",
    "    wap = (df['bid_price1'] * df['ask_size1'] + df['ask_price1'] * df['bid_size1']) / (df['bid_size1'] + df['ask_size1'])\n",
    "    return wap\n",
    "\n",
    "# Function to calculate second WAP\n",
    "def calc_wap2(df):\n",
    "    wap = (df['bid_price2'] * df['ask_size2'] + df['ask_price2'] * df['bid_size2']) / (df['bid_size2'] + df['ask_size2'])\n",
    "    return wap\n",
    "\n",
    "def calc_wap3(df):\n",
    "    wap = (df['bid_price1'] * df['bid_size1'] + df['ask_price1'] * df['ask_size1']) / (df['bid_size1'] + df['ask_size1'])\n",
    "    return wap\n",
    "\n",
    "def calc_wap4(df):\n",
    "    wap = (df['bid_price2'] * df['bid_size2'] + df['ask_price2'] * df['ask_size2']) / (df['bid_size2'] + df['ask_size2'])\n",
    "    return wap\n",
    "\n",
    "# Function to calculate the log of the return\n",
    "# Remember that logb(x / y) = logb(x) - logb(y)\n",
    "def log_return(series):\n",
    "    return np.log(series).diff()\n",
    "\n",
    "# Calculate the realized volatility\n",
    "def realized_volatility(series):\n",
    "    return np.sqrt(np.sum(series**2))\n",
    "\n",
    "# Function to count unique elements of a series\n",
    "def count_unique(series):\n",
    "    return len(np.unique(series))\n",
    "\n",
    "# Function to preprocess book data (for each stock id)\n",
    "def book_preprocessor(file_path):\n",
    "    df = pd.read_parquet(file_path)\n",
    "    # Calculate Wap\n",
    "    df['wap1'] = calc_wap1(df)\n",
    "    df['wap2'] = calc_wap2(df)\n",
    "    df['wap3'] = calc_wap3(df)\n",
    "    df['wap4'] = calc_wap4(df)\n",
    "    # Calculate log returns\n",
    "    df['log_return1'] = df.groupby(['time_id'])['wap1'].apply(log_return)\n",
    "    df['log_return2'] = df.groupby(['time_id'])['wap2'].apply(log_return)\n",
    "    df['log_return3'] = df.groupby(['time_id'])['wap3'].apply(log_return)\n",
    "    df['log_return4'] = df.groupby(['time_id'])['wap4'].apply(log_return)\n",
    "    # Calculate wap balance\n",
    "    df['wap_balance'] = abs(df['wap1'] - df['wap2'])\n",
    "    # Calculate spread\n",
    "    df['price_spread'] = (df['ask_price1'] - df['bid_price1']) / ((df['ask_price1'] + df['bid_price1']) / 2)\n",
    "    df['price_spread2'] = (df['ask_price2'] - df['bid_price2']) / ((df['ask_price2'] + df['bid_price2']) / 2)\n",
    "    df['bid_spread'] = df['bid_price1'] - df['bid_price2']\n",
    "    df['ask_spread'] = df['ask_price1'] - df['ask_price2']\n",
    "    df[\"bid_ask_spread\"] = abs(df['bid_spread'] - df['ask_spread'])\n",
    "    df['total_volume'] = (df['ask_size1'] + df['ask_size2']) + (df['bid_size1'] + df['bid_size2'])\n",
    "    df['volume_imbalance'] = abs((df['ask_size1'] + df['ask_size2']) - (df['bid_size1'] + df['bid_size2']))\n",
    "    \n",
    "    # Dict for aggregations\n",
    "    create_feature_dict = {\n",
    "        'wap1': [np.sum, np.std],\n",
    "        'wap2': [np.sum, np.std],\n",
    "        'wap3': [np.sum, np.std],\n",
    "        'wap4': [np.sum, np.std],\n",
    "        'log_return1': [realized_volatility],\n",
    "        'log_return2': [realized_volatility],\n",
    "        'log_return3': [realized_volatility],\n",
    "        'log_return4': [realized_volatility],\n",
    "        'wap_balance': [np.sum, np.max],\n",
    "        'price_spread':[np.sum, np.max],\n",
    "        'price_spread2':[np.sum, np.max],\n",
    "        'bid_spread':[np.sum, np.max],\n",
    "        'ask_spread':[np.sum, np.max],\n",
    "        'total_volume':[np.sum, np.max],\n",
    "        'volume_imbalance':[np.sum, np.max],\n",
    "        \"bid_ask_spread\":[np.sum,  np.max],\n",
    "    }\n",
    "    create_feature_dict_time = {\n",
    "        'log_return1': [realized_volatility],\n",
    "        'log_return2': [realized_volatility],\n",
    "        'log_return3': [realized_volatility],\n",
    "        'log_return4': [realized_volatility],\n",
    "    }\n",
    "    \n",
    "    # Function to get group stats for different windows (seconds in bucket)\n",
    "    def get_stats_window(fe_dict,seconds_in_bucket, add_suffix = False):\n",
    "        # Group by the window\n",
    "        df_feature = df[df['seconds_in_bucket'] >= seconds_in_bucket].groupby(['time_id']).agg(fe_dict).reset_index()\n",
    "        # Rename columns joining suffix\n",
    "        df_feature.columns = ['_'.join(col) for col in df_feature.columns]\n",
    "        # Add a suffix to differentiate windows\n",
    "        if add_suffix:\n",
    "            df_feature = df_feature.add_suffix('_' + str(seconds_in_bucket))\n",
    "        return df_feature\n",
    "    \n",
    "    # Get the stats for different windows\n",
    "    df_feature = get_stats_window(create_feature_dict,seconds_in_bucket = 0, add_suffix = False)\n",
    "    df_feature_500 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 500, add_suffix = True)\n",
    "    df_feature_400 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 400, add_suffix = True)\n",
    "    df_feature_300 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 300, add_suffix = True)\n",
    "    df_feature_200 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 200, add_suffix = True)\n",
    "    df_feature_100 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 100, add_suffix = True)\n",
    "\n",
    "    # Merge all\n",
    "    df_feature = df_feature.merge(df_feature_500, how = 'left', left_on = 'time_id_', right_on = 'time_id__500')\n",
    "    df_feature = df_feature.merge(df_feature_400, how = 'left', left_on = 'time_id_', right_on = 'time_id__400')\n",
    "    df_feature = df_feature.merge(df_feature_300, how = 'left', left_on = 'time_id_', right_on = 'time_id__300')\n",
    "    df_feature = df_feature.merge(df_feature_200, how = 'left', left_on = 'time_id_', right_on = 'time_id__200')\n",
    "    df_feature = df_feature.merge(df_feature_100, how = 'left', left_on = 'time_id_', right_on = 'time_id__100')\n",
    "    # Drop unnecesary time_ids\n",
    "    df_feature.drop(['time_id__500','time_id__400', 'time_id__300', 'time_id__200','time_id__100'], axis = 1, inplace = True)\n",
    "    \n",
    "    \n",
    "    # Create row_id so we can merge\n",
    "    stock_id = file_path.split('=')[1]\n",
    "    df_feature['row_id'] = df_feature['time_id_'].apply(lambda x: f'{stock_id}-{x}')\n",
    "    df_feature.drop(['time_id_'], axis = 1, inplace = True)\n",
    "    return df_feature\n",
    "\n",
    "# Function to preprocess trade data (for each stock id)\n",
    "def trade_preprocessor(file_path):\n",
    "    df = pd.read_parquet(file_path)\n",
    "    df['log_return'] = df.groupby('time_id')['price'].apply(log_return)\n",
    "    df['amount']=df['price']*df['size']\n",
    "    # Dict for aggregations\n",
    "    create_feature_dict = {\n",
    "        'log_return':[realized_volatility],\n",
    "        'seconds_in_bucket':[count_unique],\n",
    "        'size':[np.sum, np.max, np.min],\n",
    "        'order_count':[np.sum,np.max],\n",
    "        'amount':[np.sum,np.max,np.min],\n",
    "    }\n",
    "    create_feature_dict_time = {\n",
    "        'log_return':[realized_volatility],\n",
    "        'seconds_in_bucket':[count_unique],\n",
    "        'size':[np.sum],\n",
    "        'order_count':[np.sum],\n",
    "    }\n",
    "    # Function to get group stats for different windows (seconds in bucket)\n",
    "    def get_stats_window(fe_dict,seconds_in_bucket, add_suffix = False):\n",
    "        # Group by the window\n",
    "        df_feature = df[df['seconds_in_bucket'] >= seconds_in_bucket].groupby(['time_id']).agg(fe_dict).reset_index()\n",
    "        # Rename columns joining suffix\n",
    "        df_feature.columns = ['_'.join(col) for col in df_feature.columns]\n",
    "        # Add a suffix to differentiate windows\n",
    "        if add_suffix:\n",
    "            df_feature = df_feature.add_suffix('_' + str(seconds_in_bucket))\n",
    "        return df_feature\n",
    "    \n",
    "\n",
    "    # Get the stats for different windows\n",
    "    df_feature = get_stats_window(create_feature_dict,seconds_in_bucket = 0, add_suffix = False)\n",
    "    df_feature_500 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 500, add_suffix = True)\n",
    "    df_feature_400 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 400, add_suffix = True)\n",
    "    df_feature_300 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 300, add_suffix = True)\n",
    "    df_feature_200 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 200, add_suffix = True)\n",
    "    df_feature_100 = get_stats_window(create_feature_dict_time,seconds_in_bucket = 100, add_suffix = True)\n",
    "    \n",
    "    def tendency(price, vol):    \n",
    "        df_diff = np.diff(price)\n",
    "        val = (df_diff/price[1:])*100\n",
    "        power = np.sum(val*vol[1:])\n",
    "        return(power)\n",
    "    \n",
    "    lis = []\n",
    "    for n_time_id in df['time_id'].unique():\n",
    "        df_id = df[df['time_id'] == n_time_id]        \n",
    "        tendencyV = tendency(df_id['price'].values, df_id['size'].values)      \n",
    "        f_max = np.sum(df_id['price'].values > np.mean(df_id['price'].values))\n",
    "        f_min = np.sum(df_id['price'].values < np.mean(df_id['price'].values))\n",
    "        df_max =  np.sum(np.diff(df_id['price'].values) > 0)\n",
    "        df_min =  np.sum(np.diff(df_id['price'].values) < 0)\n",
    "        # new\n",
    "        abs_diff = np.median(np.abs( df_id['price'].values - np.mean(df_id['price'].values)))        \n",
    "        energy = np.mean(df_id['price'].values**2)\n",
    "        iqr_p = np.percentile(df_id['price'].values,75) - np.percentile(df_id['price'].values,25)\n",
    "        \n",
    "        # vol vars\n",
    "        \n",
    "        abs_diff_v = np.median(np.abs( df_id['size'].values - np.mean(df_id['size'].values)))        \n",
    "        energy_v = np.sum(df_id['size'].values**2)\n",
    "        iqr_p_v = np.percentile(df_id['size'].values,75) - np.percentile(df_id['size'].values,25)\n",
    "        \n",
    "        lis.append({'time_id':n_time_id,'tendency':tendencyV,'f_max':f_max,'f_min':f_min,'df_max':df_max,'df_min':df_min,\n",
    "                   'abs_diff':abs_diff,'energy':energy,'iqr_p':iqr_p,'abs_diff_v':abs_diff_v,'energy_v':energy_v,'iqr_p_v':iqr_p_v})\n",
    "    \n",
    "    df_lr = pd.DataFrame(lis)\n",
    "    \n",
    "    df_feature = df_feature.merge(df_lr, how = 'left', left_on = 'time_id_', right_on = 'time_id')\n",
    "    \n",
    "    # Merge all\n",
    "    df_feature = df_feature.merge(df_feature_500, how = 'left', left_on = 'time_id_', right_on = 'time_id__500')\n",
    "    df_feature = df_feature.merge(df_feature_400, how = 'left', left_on = 'time_id_', right_on = 'time_id__400')\n",
    "    df_feature = df_feature.merge(df_feature_300, how = 'left', left_on = 'time_id_', right_on = 'time_id__300')\n",
    "    df_feature = df_feature.merge(df_feature_200, how = 'left', left_on = 'time_id_', right_on = 'time_id__200')\n",
    "    df_feature = df_feature.merge(df_feature_100, how = 'left', left_on = 'time_id_', right_on = 'time_id__100')\n",
    "    # Drop unnecesary time_ids\n",
    "    df_feature.drop(['time_id__500','time_id__400', 'time_id__300', 'time_id__200','time_id','time_id__100'], axis = 1, inplace = True)\n",
    "    \n",
    "    \n",
    "    df_feature = df_feature.add_prefix('trade_')\n",
    "    stock_id = file_path.split('=')[1]\n",
    "    df_feature['row_id'] = df_feature['trade_time_id_'].apply(lambda x:f'{stock_id}-{x}')\n",
    "    df_feature.drop(['trade_time_id_'], axis = 1, inplace = True)\n",
    "    return df_feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ffb25ca6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Function to read our base train and test set\n",
    "def read_train_test():\n",
    "    train = pd.read_csv('../input/optiver-realized-volatility-prediction/train.csv')\n",
    "#     test = pd.read_csv('../input/optiver-realized-volatility-prediction/test.csv')\n",
    "    # Create a key to merge with book and trade data\n",
    "    train['row_id'] = train['stock_id'].astype(str) + '-' + train['time_id'].astype(str)\n",
    "#     test['row_id'] = test['stock_id'].astype(str) + '-' + test['time_id'].astype(str)\n",
    "    #print(f'Our training set has {train.shape[0]} rows')\n",
    "    return train"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "d7229a4a",
   "metadata": {},
   "outputs": [],
   "source": [
    "train = read_train_test()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a452c02a",
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_id = 14\n",
    "\n",
    "file_path_book = data_dir + \"book_train.parquet/stock_id=\" + str(stock_id)\n",
    "file_path_trade = data_dir + \"trade_train.parquet/stock_id=\" + str(stock_id)\n",
    "df_tmp = pd.merge(book_preprocessor(file_path_book), trade_preprocessor(file_path_trade), on = 'row_id', how = 'left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "465457a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0           14-5\n",
       "1          14-11\n",
       "2          14-16\n",
       "3          14-31\n",
       "4          14-62\n",
       "          ...   \n",
       "3825    14-32751\n",
       "3826    14-32753\n",
       "3827    14-32758\n",
       "3828    14-32763\n",
       "3829    14-32767\n",
       "Name: row_id, Length: 3830, dtype: object"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_tmp['row_id']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "c2653a9d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3 4 3 1 3 0 1 3 5 1 0 4 3 3 3 3 3 1 3 3 6 0 0 3 6 3 0 3 6 3 6 3 3 0 4 6 3\n",
      " 6 3 3 3 0 3 3 0 4 3 3 3 4 0 6 6 6 1 4 1 3 0 3 3 0 3 0 0 6 4 0 6 4 5 2 6 4\n",
      " 4 3 4 0 6 4 4 3 0 0 4 4 6 6 3 4 0 3 3 3 3 6 0 6 6 0 0 3 0 0 3 3 0 0 3 4 3\n",
      " 4]\n",
      "[5, 10, 22, 23, 29, 36, 44, 48, 56, 66, 69, 72, 73, 76, 87, 94, 95, 102, 109, 112, 113, 115, 116, 120, 122]\n",
      "[3, 6, 9, 18, 61, 63]\n",
      "[81]\n",
      "[0, 2, 4, 7, 13, 14, 15, 16, 17, 19, 20, 26, 28, 30, 32, 34, 35, 39, 41, 42, 43, 46, 47, 51, 52, 53, 64, 67, 68, 70, 85, 93, 100, 103, 104, 105, 107, 114, 118, 119, 123, 125]\n",
      "[1, 11, 37, 50, 55, 62, 75, 78, 83, 84, 86, 89, 90, 96, 97, 101, 124, 126]\n",
      "[8, 80]\n",
      "[21, 27, 31, 33, 38, 40, 58, 59, 60, 74, 77, 82, 88, 98, 99, 108, 110, 111]\n"
     ]
    }
   ],
   "source": [
    "from sklearn.cluster import KMeans\n",
    "# making agg features\n",
    "\n",
    "train_p = pd.read_csv('../input/optiver-realized-volatility-prediction/train.csv')\n",
    "train_p = train_p.pivot(index='time_id', columns='stock_id', values='target')\n",
    "\n",
    "corr = train_p.corr()\n",
    "\n",
    "ids = corr.index\n",
    "\n",
    "kmeans = KMeans(n_clusters=7, random_state=0).fit(corr.values)\n",
    "print(kmeans.labels_)\n",
    "\n",
    "l = []\n",
    "for n in range(7):\n",
    "    l.append ( [ (x-1) for x in ( (ids+1)*(kmeans.labels_ == n)) if x > 0] )\n",
    "    \n",
    "\n",
    "mat = []\n",
    "matTest = []\n",
    "\n",
    "n = 0\n",
    "for ind in l:\n",
    "    print(ind)\n",
    "    newDf = train.loc[train['stock_id'].isin(ind) ]\n",
    "    newDf = newDf.groupby(['time_id']).agg(np.nanmean)\n",
    "    newDf.loc[:,'stock_id'] = str(n)+'c1'\n",
    "    mat.append ( newDf )\n",
    "    \n",
    "#     newDf = test.loc[test['stock_id'].isin(ind) ]    \n",
    "#     newDf = newDf.groupby(['time_id']).agg(np.nanmean)\n",
    "#     newDf.loc[:,'stock_id'] = str(n)+'c1'\n",
    "#     matTest.append ( newDf )\n",
    "    \n",
    "    n+=1\n",
    "    \n",
    "mat1 = pd.concat(mat).reset_index()\n",
    "mat1.drop(columns=['target'],inplace=True)\n",
    "\n",
    "# mat2 = pd.concat(matTest).reset_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "bdda5d09",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>time_id</th>\n",
       "      <th>stock_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "      <td>0c1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>11</td>\n",
       "      <td>0c1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>16</td>\n",
       "      <td>0c1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>31</td>\n",
       "      <td>0c1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>62</td>\n",
       "      <td>0c1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26805</th>\n",
       "      <td>32751</td>\n",
       "      <td>6c1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26806</th>\n",
       "      <td>32753</td>\n",
       "      <td>6c1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26807</th>\n",
       "      <td>32758</td>\n",
       "      <td>6c1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26808</th>\n",
       "      <td>32763</td>\n",
       "      <td>6c1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26809</th>\n",
       "      <td>32767</td>\n",
       "      <td>6c1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>26810 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       time_id stock_id\n",
       "0            5      0c1\n",
       "1           11      0c1\n",
       "2           16      0c1\n",
       "3           31      0c1\n",
       "4           62      0c1\n",
       "...        ...      ...\n",
       "26805    32751      6c1\n",
       "26806    32753      6c1\n",
       "26807    32758      6c1\n",
       "26808    32763      6c1\n",
       "26809    32767      6c1\n",
       "\n",
       "[26810 rows x 2 columns]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mat1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "3e3e635a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>stock_id</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>115</th>\n",
       "      <th>116</th>\n",
       "      <th>118</th>\n",
       "      <th>119</th>\n",
       "      <th>120</th>\n",
       "      <th>122</th>\n",
       "      <th>123</th>\n",
       "      <th>124</th>\n",
       "      <th>125</th>\n",
       "      <th>126</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.004136</td>\n",
       "      <td>0.006340</td>\n",
       "      <td>0.001848</td>\n",
       "      <td>0.005300</td>\n",
       "      <td>0.004468</td>\n",
       "      <td>0.006234</td>\n",
       "      <td>0.007651</td>\n",
       "      <td>0.003624</td>\n",
       "      <td>0.010036</td>\n",
       "      <td>0.007291</td>\n",
       "      <td>...</td>\n",
       "      <td>0.004267</td>\n",
       "      <td>0.007944</td>\n",
       "      <td>0.003336</td>\n",
       "      <td>0.002571</td>\n",
       "      <td>0.003035</td>\n",
       "      <td>0.004862</td>\n",
       "      <td>0.002942</td>\n",
       "      <td>0.004112</td>\n",
       "      <td>0.001919</td>\n",
       "      <td>0.008067</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.001445</td>\n",
       "      <td>0.002099</td>\n",
       "      <td>0.000806</td>\n",
       "      <td>0.002774</td>\n",
       "      <td>0.001852</td>\n",
       "      <td>0.002562</td>\n",
       "      <td>0.004670</td>\n",
       "      <td>0.002458</td>\n",
       "      <td>0.002291</td>\n",
       "      <td>0.002529</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001382</td>\n",
       "      <td>0.002469</td>\n",
       "      <td>0.002030</td>\n",
       "      <td>0.000839</td>\n",
       "      <td>0.001271</td>\n",
       "      <td>0.002095</td>\n",
       "      <td>0.001518</td>\n",
       "      <td>0.001891</td>\n",
       "      <td>0.001123</td>\n",
       "      <td>0.003965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0.002168</td>\n",
       "      <td>0.002456</td>\n",
       "      <td>0.001581</td>\n",
       "      <td>0.002986</td>\n",
       "      <td>0.002213</td>\n",
       "      <td>0.003253</td>\n",
       "      <td>0.004303</td>\n",
       "      <td>0.002178</td>\n",
       "      <td>0.001841</td>\n",
       "      <td>0.003299</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001949</td>\n",
       "      <td>0.002195</td>\n",
       "      <td>0.003410</td>\n",
       "      <td>0.002569</td>\n",
       "      <td>0.002137</td>\n",
       "      <td>0.001893</td>\n",
       "      <td>0.002131</td>\n",
       "      <td>0.002428</td>\n",
       "      <td>0.001548</td>\n",
       "      <td>0.003161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>0.002195</td>\n",
       "      <td>0.002807</td>\n",
       "      <td>0.001599</td>\n",
       "      <td>0.004437</td>\n",
       "      <td>0.002256</td>\n",
       "      <td>0.003072</td>\n",
       "      <td>0.005401</td>\n",
       "      <td>0.002149</td>\n",
       "      <td>0.003997</td>\n",
       "      <td>0.003696</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002035</td>\n",
       "      <td>0.002298</td>\n",
       "      <td>0.005674</td>\n",
       "      <td>0.002115</td>\n",
       "      <td>0.001734</td>\n",
       "      <td>0.003509</td>\n",
       "      <td>0.001078</td>\n",
       "      <td>0.002182</td>\n",
       "      <td>0.001251</td>\n",
       "      <td>0.003593</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>0.001747</td>\n",
       "      <td>0.004312</td>\n",
       "      <td>0.001503</td>\n",
       "      <td>0.003408</td>\n",
       "      <td>0.002102</td>\n",
       "      <td>0.002824</td>\n",
       "      <td>0.004562</td>\n",
       "      <td>0.002203</td>\n",
       "      <td>0.003923</td>\n",
       "      <td>0.003689</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002459</td>\n",
       "      <td>0.003704</td>\n",
       "      <td>0.003914</td>\n",
       "      <td>0.001549</td>\n",
       "      <td>0.001470</td>\n",
       "      <td>0.002151</td>\n",
       "      <td>0.001253</td>\n",
       "      <td>0.002382</td>\n",
       "      <td>0.001324</td>\n",
       "      <td>0.003496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32751</th>\n",
       "      <td>0.002611</td>\n",
       "      <td>0.003741</td>\n",
       "      <td>0.001662</td>\n",
       "      <td>0.005943</td>\n",
       "      <td>0.002007</td>\n",
       "      <td>0.003966</td>\n",
       "      <td>0.004974</td>\n",
       "      <td>0.002287</td>\n",
       "      <td>0.005161</td>\n",
       "      <td>0.006234</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001733</td>\n",
       "      <td>0.003795</td>\n",
       "      <td>0.002121</td>\n",
       "      <td>0.001744</td>\n",
       "      <td>0.001705</td>\n",
       "      <td>0.002850</td>\n",
       "      <td>0.001643</td>\n",
       "      <td>0.002936</td>\n",
       "      <td>0.001103</td>\n",
       "      <td>0.003461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32753</th>\n",
       "      <td>0.001190</td>\n",
       "      <td>0.012414</td>\n",
       "      <td>0.000925</td>\n",
       "      <td>0.002845</td>\n",
       "      <td>0.002449</td>\n",
       "      <td>0.001542</td>\n",
       "      <td>0.003272</td>\n",
       "      <td>0.001529</td>\n",
       "      <td>0.001301</td>\n",
       "      <td>0.002501</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001252</td>\n",
       "      <td>0.001612</td>\n",
       "      <td>0.001842</td>\n",
       "      <td>0.001518</td>\n",
       "      <td>0.001436</td>\n",
       "      <td>0.001079</td>\n",
       "      <td>0.002507</td>\n",
       "      <td>0.001683</td>\n",
       "      <td>0.001046</td>\n",
       "      <td>0.003113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32758</th>\n",
       "      <td>0.004264</td>\n",
       "      <td>0.002868</td>\n",
       "      <td>0.001188</td>\n",
       "      <td>0.003415</td>\n",
       "      <td>0.002648</td>\n",
       "      <td>0.003377</td>\n",
       "      <td>0.004154</td>\n",
       "      <td>0.001977</td>\n",
       "      <td>0.003751</td>\n",
       "      <td>0.003578</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002461</td>\n",
       "      <td>0.004024</td>\n",
       "      <td>0.003248</td>\n",
       "      <td>0.001840</td>\n",
       "      <td>0.001720</td>\n",
       "      <td>0.002696</td>\n",
       "      <td>0.001442</td>\n",
       "      <td>0.002811</td>\n",
       "      <td>0.001196</td>\n",
       "      <td>0.004070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32763</th>\n",
       "      <td>0.004352</td>\n",
       "      <td>0.004902</td>\n",
       "      <td>0.004879</td>\n",
       "      <td>0.003664</td>\n",
       "      <td>0.005086</td>\n",
       "      <td>0.006443</td>\n",
       "      <td>0.005483</td>\n",
       "      <td>0.002998</td>\n",
       "      <td>0.002819</td>\n",
       "      <td>0.004607</td>\n",
       "      <td>...</td>\n",
       "      <td>0.004302</td>\n",
       "      <td>0.003970</td>\n",
       "      <td>0.006995</td>\n",
       "      <td>0.004559</td>\n",
       "      <td>0.003190</td>\n",
       "      <td>0.002388</td>\n",
       "      <td>0.003236</td>\n",
       "      <td>0.003679</td>\n",
       "      <td>0.005127</td>\n",
       "      <td>0.003357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32767</th>\n",
       "      <td>0.001084</td>\n",
       "      <td>0.002204</td>\n",
       "      <td>0.001164</td>\n",
       "      <td>0.004682</td>\n",
       "      <td>0.003137</td>\n",
       "      <td>0.003817</td>\n",
       "      <td>0.004041</td>\n",
       "      <td>0.002707</td>\n",
       "      <td>0.001861</td>\n",
       "      <td>0.003242</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001810</td>\n",
       "      <td>0.001706</td>\n",
       "      <td>0.002580</td>\n",
       "      <td>0.001764</td>\n",
       "      <td>0.001369</td>\n",
       "      <td>0.002385</td>\n",
       "      <td>0.001625</td>\n",
       "      <td>0.002833</td>\n",
       "      <td>0.001196</td>\n",
       "      <td>0.002090</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3830 rows × 112 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "stock_id       0         1         2         3         4         5    \\\n",
       "time_id                                                                \n",
       "5         0.004136  0.006340  0.001848  0.005300  0.004468  0.006234   \n",
       "11        0.001445  0.002099  0.000806  0.002774  0.001852  0.002562   \n",
       "16        0.002168  0.002456  0.001581  0.002986  0.002213  0.003253   \n",
       "31        0.002195  0.002807  0.001599  0.004437  0.002256  0.003072   \n",
       "62        0.001747  0.004312  0.001503  0.003408  0.002102  0.002824   \n",
       "...            ...       ...       ...       ...       ...       ...   \n",
       "32751     0.002611  0.003741  0.001662  0.005943  0.002007  0.003966   \n",
       "32753     0.001190  0.012414  0.000925  0.002845  0.002449  0.001542   \n",
       "32758     0.004264  0.002868  0.001188  0.003415  0.002648  0.003377   \n",
       "32763     0.004352  0.004902  0.004879  0.003664  0.005086  0.006443   \n",
       "32767     0.001084  0.002204  0.001164  0.004682  0.003137  0.003817   \n",
       "\n",
       "stock_id       6         7         8         9    ...       115       116  \\\n",
       "time_id                                           ...                       \n",
       "5         0.007651  0.003624  0.010036  0.007291  ...  0.004267  0.007944   \n",
       "11        0.004670  0.002458  0.002291  0.002529  ...  0.001382  0.002469   \n",
       "16        0.004303  0.002178  0.001841  0.003299  ...  0.001949  0.002195   \n",
       "31        0.005401  0.002149  0.003997  0.003696  ...  0.002035  0.002298   \n",
       "62        0.004562  0.002203  0.003923  0.003689  ...  0.002459  0.003704   \n",
       "...            ...       ...       ...       ...  ...       ...       ...   \n",
       "32751     0.004974  0.002287  0.005161  0.006234  ...  0.001733  0.003795   \n",
       "32753     0.003272  0.001529  0.001301  0.002501  ...  0.001252  0.001612   \n",
       "32758     0.004154  0.001977  0.003751  0.003578  ...  0.002461  0.004024   \n",
       "32763     0.005483  0.002998  0.002819  0.004607  ...  0.004302  0.003970   \n",
       "32767     0.004041  0.002707  0.001861  0.003242  ...  0.001810  0.001706   \n",
       "\n",
       "stock_id       118       119       120       122       123       124  \\\n",
       "time_id                                                                \n",
       "5         0.003336  0.002571  0.003035  0.004862  0.002942  0.004112   \n",
       "11        0.002030  0.000839  0.001271  0.002095  0.001518  0.001891   \n",
       "16        0.003410  0.002569  0.002137  0.001893  0.002131  0.002428   \n",
       "31        0.005674  0.002115  0.001734  0.003509  0.001078  0.002182   \n",
       "62        0.003914  0.001549  0.001470  0.002151  0.001253  0.002382   \n",
       "...            ...       ...       ...       ...       ...       ...   \n",
       "32751     0.002121  0.001744  0.001705  0.002850  0.001643  0.002936   \n",
       "32753     0.001842  0.001518  0.001436  0.001079  0.002507  0.001683   \n",
       "32758     0.003248  0.001840  0.001720  0.002696  0.001442  0.002811   \n",
       "32763     0.006995  0.004559  0.003190  0.002388  0.003236  0.003679   \n",
       "32767     0.002580  0.001764  0.001369  0.002385  0.001625  0.002833   \n",
       "\n",
       "stock_id       125       126  \n",
       "time_id                       \n",
       "5         0.001919  0.008067  \n",
       "11        0.001123  0.003965  \n",
       "16        0.001548  0.003161  \n",
       "31        0.001251  0.003593  \n",
       "62        0.001324  0.003496  \n",
       "...            ...       ...  \n",
       "32751     0.001103  0.003461  \n",
       "32753     0.001046  0.003113  \n",
       "32758     0.001196  0.004070  \n",
       "32763     0.005127  0.003357  \n",
       "32767     0.001196  0.002090  \n",
       "\n",
       "[3830 rows x 112 columns]"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "3c43803c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>stock_id</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "      <th>4</th>\n",
       "      <th>5</th>\n",
       "      <th>6</th>\n",
       "      <th>7</th>\n",
       "      <th>8</th>\n",
       "      <th>9</th>\n",
       "      <th>...</th>\n",
       "      <th>115</th>\n",
       "      <th>116</th>\n",
       "      <th>118</th>\n",
       "      <th>119</th>\n",
       "      <th>120</th>\n",
       "      <th>122</th>\n",
       "      <th>123</th>\n",
       "      <th>124</th>\n",
       "      <th>125</th>\n",
       "      <th>126</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>time_id</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.004136</td>\n",
       "      <td>0.006340</td>\n",
       "      <td>0.001848</td>\n",
       "      <td>0.005300</td>\n",
       "      <td>0.004468</td>\n",
       "      <td>0.006234</td>\n",
       "      <td>0.007651</td>\n",
       "      <td>0.003624</td>\n",
       "      <td>0.010036</td>\n",
       "      <td>0.007291</td>\n",
       "      <td>...</td>\n",
       "      <td>0.004267</td>\n",
       "      <td>0.007944</td>\n",
       "      <td>0.003336</td>\n",
       "      <td>0.002571</td>\n",
       "      <td>0.003035</td>\n",
       "      <td>0.004862</td>\n",
       "      <td>0.002942</td>\n",
       "      <td>0.004112</td>\n",
       "      <td>0.001919</td>\n",
       "      <td>0.008067</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.001445</td>\n",
       "      <td>0.002099</td>\n",
       "      <td>0.000806</td>\n",
       "      <td>0.002774</td>\n",
       "      <td>0.001852</td>\n",
       "      <td>0.002562</td>\n",
       "      <td>0.004670</td>\n",
       "      <td>0.002458</td>\n",
       "      <td>0.002291</td>\n",
       "      <td>0.002529</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001382</td>\n",
       "      <td>0.002469</td>\n",
       "      <td>0.002030</td>\n",
       "      <td>0.000839</td>\n",
       "      <td>0.001271</td>\n",
       "      <td>0.002095</td>\n",
       "      <td>0.001518</td>\n",
       "      <td>0.001891</td>\n",
       "      <td>0.001123</td>\n",
       "      <td>0.003965</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0.002168</td>\n",
       "      <td>0.002456</td>\n",
       "      <td>0.001581</td>\n",
       "      <td>0.002986</td>\n",
       "      <td>0.002213</td>\n",
       "      <td>0.003253</td>\n",
       "      <td>0.004303</td>\n",
       "      <td>0.002178</td>\n",
       "      <td>0.001841</td>\n",
       "      <td>0.003299</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001949</td>\n",
       "      <td>0.002195</td>\n",
       "      <td>0.003410</td>\n",
       "      <td>0.002569</td>\n",
       "      <td>0.002137</td>\n",
       "      <td>0.001893</td>\n",
       "      <td>0.002131</td>\n",
       "      <td>0.002428</td>\n",
       "      <td>0.001548</td>\n",
       "      <td>0.003161</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>0.002195</td>\n",
       "      <td>0.002807</td>\n",
       "      <td>0.001599</td>\n",
       "      <td>0.004437</td>\n",
       "      <td>0.002256</td>\n",
       "      <td>0.003072</td>\n",
       "      <td>0.005401</td>\n",
       "      <td>0.002149</td>\n",
       "      <td>0.003997</td>\n",
       "      <td>0.003696</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002035</td>\n",
       "      <td>0.002298</td>\n",
       "      <td>0.005674</td>\n",
       "      <td>0.002115</td>\n",
       "      <td>0.001734</td>\n",
       "      <td>0.003509</td>\n",
       "      <td>0.001078</td>\n",
       "      <td>0.002182</td>\n",
       "      <td>0.001251</td>\n",
       "      <td>0.003593</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>0.001747</td>\n",
       "      <td>0.004312</td>\n",
       "      <td>0.001503</td>\n",
       "      <td>0.003408</td>\n",
       "      <td>0.002102</td>\n",
       "      <td>0.002824</td>\n",
       "      <td>0.004562</td>\n",
       "      <td>0.002203</td>\n",
       "      <td>0.003923</td>\n",
       "      <td>0.003689</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002459</td>\n",
       "      <td>0.003704</td>\n",
       "      <td>0.003914</td>\n",
       "      <td>0.001549</td>\n",
       "      <td>0.001470</td>\n",
       "      <td>0.002151</td>\n",
       "      <td>0.001253</td>\n",
       "      <td>0.002382</td>\n",
       "      <td>0.001324</td>\n",
       "      <td>0.003496</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32751</th>\n",
       "      <td>0.002611</td>\n",
       "      <td>0.003741</td>\n",
       "      <td>0.001662</td>\n",
       "      <td>0.005943</td>\n",
       "      <td>0.002007</td>\n",
       "      <td>0.003966</td>\n",
       "      <td>0.004974</td>\n",
       "      <td>0.002287</td>\n",
       "      <td>0.005161</td>\n",
       "      <td>0.006234</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001733</td>\n",
       "      <td>0.003795</td>\n",
       "      <td>0.002121</td>\n",
       "      <td>0.001744</td>\n",
       "      <td>0.001705</td>\n",
       "      <td>0.002850</td>\n",
       "      <td>0.001643</td>\n",
       "      <td>0.002936</td>\n",
       "      <td>0.001103</td>\n",
       "      <td>0.003461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32753</th>\n",
       "      <td>0.001190</td>\n",
       "      <td>0.012414</td>\n",
       "      <td>0.000925</td>\n",
       "      <td>0.002845</td>\n",
       "      <td>0.002449</td>\n",
       "      <td>0.001542</td>\n",
       "      <td>0.003272</td>\n",
       "      <td>0.001529</td>\n",
       "      <td>0.001301</td>\n",
       "      <td>0.002501</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001252</td>\n",
       "      <td>0.001612</td>\n",
       "      <td>0.001842</td>\n",
       "      <td>0.001518</td>\n",
       "      <td>0.001436</td>\n",
       "      <td>0.001079</td>\n",
       "      <td>0.002507</td>\n",
       "      <td>0.001683</td>\n",
       "      <td>0.001046</td>\n",
       "      <td>0.003113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32758</th>\n",
       "      <td>0.004264</td>\n",
       "      <td>0.002868</td>\n",
       "      <td>0.001188</td>\n",
       "      <td>0.003415</td>\n",
       "      <td>0.002648</td>\n",
       "      <td>0.003377</td>\n",
       "      <td>0.004154</td>\n",
       "      <td>0.001977</td>\n",
       "      <td>0.003751</td>\n",
       "      <td>0.003578</td>\n",
       "      <td>...</td>\n",
       "      <td>0.002461</td>\n",
       "      <td>0.004024</td>\n",
       "      <td>0.003248</td>\n",
       "      <td>0.001840</td>\n",
       "      <td>0.001720</td>\n",
       "      <td>0.002696</td>\n",
       "      <td>0.001442</td>\n",
       "      <td>0.002811</td>\n",
       "      <td>0.001196</td>\n",
       "      <td>0.004070</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32763</th>\n",
       "      <td>0.004352</td>\n",
       "      <td>0.004902</td>\n",
       "      <td>0.004879</td>\n",
       "      <td>0.003664</td>\n",
       "      <td>0.005086</td>\n",
       "      <td>0.006443</td>\n",
       "      <td>0.005483</td>\n",
       "      <td>0.002998</td>\n",
       "      <td>0.002819</td>\n",
       "      <td>0.004607</td>\n",
       "      <td>...</td>\n",
       "      <td>0.004302</td>\n",
       "      <td>0.003970</td>\n",
       "      <td>0.006995</td>\n",
       "      <td>0.004559</td>\n",
       "      <td>0.003190</td>\n",
       "      <td>0.002388</td>\n",
       "      <td>0.003236</td>\n",
       "      <td>0.003679</td>\n",
       "      <td>0.005127</td>\n",
       "      <td>0.003357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32767</th>\n",
       "      <td>0.001084</td>\n",
       "      <td>0.002204</td>\n",
       "      <td>0.001164</td>\n",
       "      <td>0.004682</td>\n",
       "      <td>0.003137</td>\n",
       "      <td>0.003817</td>\n",
       "      <td>0.004041</td>\n",
       "      <td>0.002707</td>\n",
       "      <td>0.001861</td>\n",
       "      <td>0.003242</td>\n",
       "      <td>...</td>\n",
       "      <td>0.001810</td>\n",
       "      <td>0.001706</td>\n",
       "      <td>0.002580</td>\n",
       "      <td>0.001764</td>\n",
       "      <td>0.001369</td>\n",
       "      <td>0.002385</td>\n",
       "      <td>0.001625</td>\n",
       "      <td>0.002833</td>\n",
       "      <td>0.001196</td>\n",
       "      <td>0.002090</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3830 rows × 112 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "stock_id       0         1         2         3         4         5    \\\n",
       "time_id                                                                \n",
       "5         0.004136  0.006340  0.001848  0.005300  0.004468  0.006234   \n",
       "11        0.001445  0.002099  0.000806  0.002774  0.001852  0.002562   \n",
       "16        0.002168  0.002456  0.001581  0.002986  0.002213  0.003253   \n",
       "31        0.002195  0.002807  0.001599  0.004437  0.002256  0.003072   \n",
       "62        0.001747  0.004312  0.001503  0.003408  0.002102  0.002824   \n",
       "...            ...       ...       ...       ...       ...       ...   \n",
       "32751     0.002611  0.003741  0.001662  0.005943  0.002007  0.003966   \n",
       "32753     0.001190  0.012414  0.000925  0.002845  0.002449  0.001542   \n",
       "32758     0.004264  0.002868  0.001188  0.003415  0.002648  0.003377   \n",
       "32763     0.004352  0.004902  0.004879  0.003664  0.005086  0.006443   \n",
       "32767     0.001084  0.002204  0.001164  0.004682  0.003137  0.003817   \n",
       "\n",
       "stock_id       6         7         8         9    ...       115       116  \\\n",
       "time_id                                           ...                       \n",
       "5         0.007651  0.003624  0.010036  0.007291  ...  0.004267  0.007944   \n",
       "11        0.004670  0.002458  0.002291  0.002529  ...  0.001382  0.002469   \n",
       "16        0.004303  0.002178  0.001841  0.003299  ...  0.001949  0.002195   \n",
       "31        0.005401  0.002149  0.003997  0.003696  ...  0.002035  0.002298   \n",
       "62        0.004562  0.002203  0.003923  0.003689  ...  0.002459  0.003704   \n",
       "...            ...       ...       ...       ...  ...       ...       ...   \n",
       "32751     0.004974  0.002287  0.005161  0.006234  ...  0.001733  0.003795   \n",
       "32753     0.003272  0.001529  0.001301  0.002501  ...  0.001252  0.001612   \n",
       "32758     0.004154  0.001977  0.003751  0.003578  ...  0.002461  0.004024   \n",
       "32763     0.005483  0.002998  0.002819  0.004607  ...  0.004302  0.003970   \n",
       "32767     0.004041  0.002707  0.001861  0.003242  ...  0.001810  0.001706   \n",
       "\n",
       "stock_id       118       119       120       122       123       124  \\\n",
       "time_id                                                                \n",
       "5         0.003336  0.002571  0.003035  0.004862  0.002942  0.004112   \n",
       "11        0.002030  0.000839  0.001271  0.002095  0.001518  0.001891   \n",
       "16        0.003410  0.002569  0.002137  0.001893  0.002131  0.002428   \n",
       "31        0.005674  0.002115  0.001734  0.003509  0.001078  0.002182   \n",
       "62        0.003914  0.001549  0.001470  0.002151  0.001253  0.002382   \n",
       "...            ...       ...       ...       ...       ...       ...   \n",
       "32751     0.002121  0.001744  0.001705  0.002850  0.001643  0.002936   \n",
       "32753     0.001842  0.001518  0.001436  0.001079  0.002507  0.001683   \n",
       "32758     0.003248  0.001840  0.001720  0.002696  0.001442  0.002811   \n",
       "32763     0.006995  0.004559  0.003190  0.002388  0.003236  0.003679   \n",
       "32767     0.002580  0.001764  0.001369  0.002385  0.001625  0.002833   \n",
       "\n",
       "stock_id       125       126  \n",
       "time_id                       \n",
       "5         0.001919  0.008067  \n",
       "11        0.001123  0.003965  \n",
       "16        0.001548  0.003161  \n",
       "31        0.001251  0.003593  \n",
       "62        0.001324  0.003496  \n",
       "...            ...       ...  \n",
       "32751     0.001103  0.003461  \n",
       "32753     0.001046  0.003113  \n",
       "32758     0.001196  0.004070  \n",
       "32763     0.005127  0.003357  \n",
       "32767     0.001196  0.002090  \n",
       "\n",
       "[3830 rows x 112 columns]"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_p"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a85ca678",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
